import plugin from '../../lib/plugins/plugin.js'
import cfg from '../../lib/config/config.js';
let waiguai = 2845484687//开挂玩家

let moshi = 1//0增加60秒1翻倍

let hf = 0
let fq = 0
let shengyv = 0
let sy = 0
let jy = 0
let qq = 0
let qq1 = 0

export class jvban extends plugin {
  constructor() {
    super({
      name: "举办",
      dsc: "举办",
      event: "message",
      priority: 600,
      rule: [
        {
          reg: '^举办你$',
          fnc: 'jbn'
        },{
          reg: '^举办$',
          fnc: 'jb'
        },{
          reg: '^取消举办$',
          fnc: 'qxjb'
        }
      ],
    })
  }
  
  async qxjb(e) {
    e.group.muteMember(qq,0);
    e.reply("举办结束");
    fq = 0
    return
  } 
  
  async jbn(e) {
    let master = cfg.masterQQ
    sy = e.group.pickMember(qq)
    shengyv = sy.mute_left
    if (shengyv == 0) {
      fq = 0
      jy = 0
    }
    if (fq == 1) {
      e.reply("已经有人被举办了哦")
      return
    }
    
    for (let msg of e.message) {
      if (msg.type =='at') {
        qq = msg.qq
        qq1 = e.user_id
        break
      }
    }
    //如果对方是群管理员或者群主则不执行
    if (!e.group.pickMember(qq).is_admin && !e.group.pickMember(qq).is_owner) {
      
    if(qq == e.self_id) {
      e.reply("反弹！")
      e.group.muteMember(qq1, 600)
      return 
    }
    if (qq == 0) {
      e.reply("未识别成功，请艾特对方使用")
      return
    }
    //如果对方是主人则不执行    
    if (master.includes(qq)  ){
      e.reply("坏坏，敢举办主人，找打！")
      e.group.muteMember(qq1, 600)
      return
    }
    
    e.group.muteMember(qq, 60)
    e.reply("举办成功，他已经被禁言60秒")
    fq = 1
    return
  }else{
    e.reply("举办成...啊哦，对方使用权限躲过了举办，你遭受了反噬喵！")
    e.group.muteMember(qq1, 300)
    return
  }}
  
  async jb(e) {
    sy = e.group.pickMember(qq)
    shengyv = sy.mute_left
    if (shengyv == 0) {
      fq = 0
      jy = 0
    }
    
    if (fq == 0) {
      e.reply("还没有人被举办哦，使用“举办你@xxx开始吧”")
       return
    }

    var num = Math.random()
    var num1 = Math.random()
    qq1 = e.user_id
    if (moshi = 0){
    jy = shengyv + 60
    hf = "增加60秒"
    }
    if (moshi = 1){
    jy = shengyv * 2
    hf = "翻倍"
    }
    
    if (waiguai == e.user_id) {
      e.group.muteMember(qq, jy)
      e.reply(`举办成功，他的禁言时间${hf}`)
      return
    }
    
    if (num < num1) {
      e.group.muteMember(qq, jy)
      e.reply(`举办成功，他的禁言时间${hf}`)
      return
    }
    
    if (num1 < num) {
      e.group.muteMember(qq, 0)
      e.group.muteMember(qq1, jy)
      e.reply(`举办失败，他的禁言时间${hf}转移至你的身上`)
      qq = e.user_id
      return
    }
  }
}